package dao

import (
	"go_server/game_server/database/mysql"
	"go_server/zinx/zlog"
)

func UpdateHeroInfo_All(sql *HeroInfo) {
	db := mysql.GetServerDBConnection()
	cols := &map[string]any{"heros": sql.Heros, "rolecells": sql.RoleCells, "heroskills": sql.HeroSkills, "herocells": sql.HeroCells}
	if err := db.Model(HeroInfo{}).Where("roleid=?", sql.RoleId).Updates(cols).Error; err != nil {
		zlog.Errorf("UpdateHeroInfo_All %v data failed: %v", sql, err)
	}
}

func UpdateHeroInfo_Heros(sql *HeroInfo) {
	db := mysql.GetServerDBConnection()
	cols := &map[string]any{"heros": sql.Heros}
	if err := db.Model(HeroInfo{}).Where("roleid=?", sql.RoleId).Updates(cols).Error; err != nil {
		zlog.Errorf("UpdateHeroInfo_Heros %v data failed: %v", sql, err)
	}
}

func UpdateHeroInfo_Cells(sql *HeroInfo) {
	db := mysql.GetServerDBConnection()
	cols := &map[string]any{"rolecells": sql.RoleCells, "herocells": sql.HeroCells}
	if err := db.Model(HeroInfo{}).Where("roleid=?", sql.RoleId).Updates(cols).Error; err != nil {
		zlog.Errorf("UpdateHeroInfo_Heros %v data failed: %v", sql, err)
	}
}
